<?php
    function get_stars($sort)
    {
        include('connect_sql.php');
        $i=0;$stars=array("暂缺","暂缺","暂缺","暂缺","暂缺","暂缺","暂缺","暂缺");
        if($sort==1)
        {
            $sql="select `user_nicename`,`user_score` from `wp_users` WHERE user_nicename!='' ORDER BY user_score DESC,user_scoreall DESC LIMIT 0,8";
            $result=mysql_query($sql,$link);
            while($stu=mysql_fetch_array($result))
            {
                $stars[$i]=$stu['user_nicename'];++$i;
            }
        }
        else
        {
            $sql="select `user_college`,`user_score` from `wp_users` WHERE user_college!=''";
            $result=mysql_query($sql,$link);
            $colleges=array( "机械与汽车工程学院"=>0,"建筑学院"=>0,"土木与交通学院"=>0,
                              "电子与信息学院"=>0,"材料科学与工程学院"=>0,"化学与化工学院"=>0,
                              "轻工与食品学院"=>0,"理学院"=>0,"经济与贸易学院"=>0,
                              "自动化科学与工程学院"=>0,"计算机科学与工程学院"=>0,"电力学院"=>0,
                              "生物科学与工程学院"=>0,"环境科学与工程学院"=>0,"软件学院"=>0,
                              "工商管理学院"=>0,"公共管理学院"=>0,"思想政治学院"=>0,
                              "外国语学院"=>0,"法学院"=>0,"新闻与传播学院"=>0,
                              "艺术学院"=>0,"体育学院"=>0,"国际教育学院"=>0,
                              "国防生教育学院"=>0,"设计学院"=>0,"其它"=>0 );
           while($stu=mysql_fetch_array($result))
           {
               $col=$stu['user_college'];
               $colleges[$col]+=$stu['user_score'];
           }
           arsort($colleges);
           foreach($colleges as $key=>$value)
           {
               if($i>=8) break;
               if($value) $stars[$i]=$key;
               ++$i;
           }
        }
        return $stars;
    }
?>

<hr />
<ol class="rank"><span class="rank_title">个人排行</span><br />
<?php
	$rank_personal = get_stars(1);
	for ($i=0; $i<8; $i++) {
		echo "<li> " . $rank_personal[$i] . "</li>";
	}
?>
</ol>
<hr />
<ol class="rank"><span class="rank_title">学院排行</span><br />
<?php
	$rank_school = get_stars(2);
	for ($i=0; $i<8; $i++) {
		echo "<li> " . $rank_school[$i] . "</li>";
	}
?>
</ol>